from typing import Optional, List

import os

AK = '2jCwbiCWReSVlPbt53f9pYhP'
SK = 'dwJ8BULLCsBMXsmtjyxNI8hkw4y0HPXq'
os.environ['QIANFAN_AK'] = AK
os.environ['QIANFAN_SK'] = SK
from langchain import PromptTemplate
from langchain.llms import QianfanLLMEndpoint
from langchain.chains import LLMChain, SimpleSequentialChain

# 创建第一条链
template = '我的邻居姓{lastname}，他生了个儿子，给他儿子起个名字'
first_prompt = PromptTemplate(
    input_variables=['lastname'], template=template
)
llm = QianfanLLMEndpoint(temperature=0.9)
first_chain = LLMChain(llm=llm, prompt=first_prompt)
# 创建第二条链
second_prompt = PromptTemplate(
    input_variables=['child_name'],
    template="邻居的儿子名字叫{child_name}，给他起一个小名"
)
second_chain = LLMChain(llm=llm, prompt=second_prompt)
overall_chain = SimpleSequentialChain(chains=[first_chain, second_chain], verbose=True)
print(overall_chain)
catchphrase=overall_chain.run('王')
print(catchphrase)